﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tree
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		//构建所需的函数；
		int i = 1;//用于表示数序，等于1表示输入第一个数，等于2表示输入第2个数。
		int j = 0;//用于表示运算法则，1为加法；2为减法；3为乘法；4为除法。
		int n = 1;
	
		int z = 0;//用于表示负数关系，等于1表示只有第一个数为负数，等于2表示只有第二个数为负数，等于3表示两个都为负数。
	

		double num1 = 0;//用于存放输入的第一个数值。
		double num2 = 0;//用于存放输入的第二个数值。
		double num3 = 0;//用于存放运算结果。



		private void equal_Click(object sender, EventArgs e)
		{
			switch(j){
				case 0:num3 = num1 + num2;break;
				case 1:num3 = num1 - num2;break;
				case 2:num3 = num1 * num2;break;
				case 3:num3 = num1 / num2;break;
			}
			textBox3.Text = "" + num3;
		}

		private void add_Click(object sender, EventArgs e)
		{
			label1.Text = "+";
			j = 0;
			i = 2;
			n = 1;
			num2 = 0;
			textBox2.Text = "";
		}

		private void sub_Click(object sender, EventArgs e)
		{
			label1.Text = "-";
			j = 1;
			i = 2;
			n = 1;
			num2 = 0;
			textBox2.Text = "";
		}

		private void mul_Click(object sender, EventArgs e)
		{
			label1.Text = "×";
			j = 2;
			i = 2;
			n = 1;
			num2 = 0;
			textBox2.Text = "";
		}

		private void div_Click(object sender, EventArgs e)
		{
			label1.Text = "÷";
			j = 3;
			i = 2;
			n = 1;
			num2 = 0;
			textBox2.Text = "";
		}

		private void clr_Click(object sender, EventArgs e)
		{
			textBox1.Text = "";
			textBox2.Text = "";
			textBox3.Text = "";
			label1.Text = "+";
			j = 0;
			i = 1;
			n = 1;
			num1 = 0;
			num2 = 0;
			
		}

		private void button0_Click(object sender, EventArgs e)
		{
			n = 0;
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			
			if (num2 == 0 && i == 2) num2++;
			if (i == 1 && n != 2) num1 = num1 * 10 ;
			if (i == 2 && n != 2) num2 = num2 * 10 ;
			u = 0;
			
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
			

		}

		private void button1_Click(object sender, EventArgs e)
		{
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			if (num1 == 0) num1 ++;
			if (num2 == 0 && i == 2) num2++;
			if (i == 1&&n!=2) num1 = num1*10 + 1;
			if (i == 2 && n != 2) num2 = num2 * 10 + 1;
			u = 0;
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
		}

		private void button2_Click(object sender, EventArgs e)
		{
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			if (num1 == 0) num1++;
			if (num2 == 0 && i == 2) num2++;
			if (i == 1 && n != 2) num1 = num1 * 10 + 2;
			if (i == 2 && n != 2) num2 = num2 * 10 + 2;
			u = 0;
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
		}

		private void button3_Click(object sender, EventArgs e)
		{
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			if (num1 == 0) num1++;
			if (num2 == 0 && i == 2) num2++;
			if (i == 1 && n != 2) num1 = num1 * 10 + 3;
			if (i == 2 && n != 2) num2 = num2 * 10 + 3;
			u = 0;
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
		}

		private void Form1_Load(object sender, EventArgs e)
		{

		}

		private void button4_Click(object sender, EventArgs e)
		{
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			if (num1 == 0) num1++;
			if (num2 == 0 && i == 2) num2++;
			if (i == 1 && n != 2) num1 = num1 * 10 + 4;
			if (i == 2 && n != 2) num2 = num2 * 10 + 4;
			u = 0;
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
		}

		private void button5_Click(object sender, EventArgs e)
		{
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			if (num1 == 0) num1++;
			if (num2 == 0 && i == 2) num2++;
			if (i == 1 && n != 2) num1 = num1 * 10 + 5;
			if (i == 2 && n != 2) num2 = num2 * 10 + 5;
			u = 0;
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
		}

		private void button6_Click(object sender, EventArgs e)
		{
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			if (num1 == 0) num1++;
			if (num2 == 0 && i == 2) num2++;
			if (i == 1 && n != 2) num1 = num1 * 10 + 6;
			if (i == 2 && n != 2) num2 = num2 * 10 + 6;
			u = 0;
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
		}

		private void button7_Click(object sender, EventArgs e)
		{
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			if (num1 == 0) num1++;
			if (num2 == 0&&i==2) num2++;
			if (i == 1 && n != 2) num1 = num1 * 10 + 7;
			if (i == 2 && n != 2) num2 = num2 * 10 + 7;
			u = 0;
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
		}

		private void button8_Click(object sender, EventArgs e)
		{
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			if (num1 == 0) num1++;
			if (num2 == 0) num2++;
			if (i == 1 && n != 2) num1 = num1 * 10 + 8;
			if (i == 2 && n != 2) num2 = num2 * 10 + 8;
			u = 0;
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
		}

		private void button9_Click(object sender, EventArgs e)
		{
			int t = 1;
			int u = 0;
			for (int m = n; m > 0; m--)
			{

				u = t * 1;

				t = t * 10;
			}
			n++;
			if (num1 == 0) num1++;
			if (num2 == 0) num2++;
			if (i == 1 && n != 2) num1 = num1 * 10 + 9;
			if (i == 2 && n != 2) num2 = num2 * 10 + 9;
			u = 0;
			textBox1.Text = "" + num1;
			textBox2.Text = "" + num2;
		}
	}
}
